<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>单向数据流2 - {{ count }}</h2>
      <child :count="count"></child>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      // 如果一定要改变props的值，那么可以将props的值作为data的初始值
      const Child = {
        props: {
          count: Number,
        },
        data() {
          return {
            num: this.count,
          };
        },
        computed: {
          abc() {
            return this.count * this.num;
          },
        },
        template: `
          <div>child子组件 - {{ num }} - <button @click="fn">btn</button> - {{ abc }}</div>
        `,
        methods: {
          fn() {
            this.num++;
          },
        },
      };

      createApp({
        data() {
          return {
            count: 5,
          };
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
